package com.start.pay.admin.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.start.common.api.Result;
import com.start.common.dataRule.DataQueryConstructor;
import com.start.core.annotations.RegisterMenu;
import com.start.core.annotations.RegisterPermission;
import com.start.core.annotations.StartLog;
import com.start.pay.core.entity.StartOrderRefundCallLogEntity;
import com.start.pay.core.service.StartOrderRefundCallLogService;
import com.start.security.annotations.DataPermission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/start/platform/order/refundCall")
@RegisterMenu(value = "平台退款订单回调", parentId = "fa082311783863635318d8e0ed424554", systemCode = "start:platform:order:refund:call", component = "views/platform/order/refundCall/index", path = "/platform/order/refundCall/index")
public class StartOrderRefundCallController {
    private static final String LOG_TITLE = "平台订单";

    @Autowired
    private StartOrderRefundCallLogService platformConfigService;

    /**
     * 列表
     */
    @GetMapping("/page")
    @DataPermission("views/platform/order/refundCall/index")
    public Result<?> list(Page<StartOrderRefundCallLogEntity> page, StartOrderRefundCallLogEntity entity) {
        QueryWrapper<StartOrderRefundCallLogEntity> queryWrapper = DataQueryConstructor.createEntity(entity);
        return Result.ok(platformConfigService.page(page, queryWrapper));
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    @StartLog(value = LOG_TITLE, action = "查询")
    @PreAuthorize("@pas.hasPermission('start:platform:order:refund:call:info')")
    @RegisterPermission(value = "start:platform:order:refund:call:info", name = "查看")
    public Result<?> info(@PathVariable("id") String id) {
        return Result.ok(platformConfigService.getById(id));
    }

    /**
     * 保存
     */
    @PostMapping("/add")
    @StartLog(value = LOG_TITLE, action = "添加")
    @PreAuthorize("@pas.hasPermission('start:platform:order:refund:call:add')")
    @RegisterPermission(value = "start:platform:order:refund:call:add", name = "添加")
    public Result<?> save(@RequestBody StartOrderRefundCallLogEntity entity) {
        platformConfigService.save(entity);

        return Result.ok();
    }

    /**
     * 修改
     */
    @PutMapping("/updateById")
    @StartLog(value = LOG_TITLE, action = "修改")
    @PreAuthorize("@pas.hasPermission('start:platform:order:refund:call:edit')")
    @RegisterPermission(value = "start:platform:order:refund:call:edit", name = "修改")
    public Result<?> update(@RequestBody StartOrderRefundCallLogEntity entity) {

        platformConfigService.updateById(entity);

        return Result.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/deleteById/{id}")
    @StartLog(value = LOG_TITLE, action = "删除")
    @PreAuthorize("@pas.hasPermission('start:platform:order:refund:call:delete')")
    @RegisterPermission(value = "start:platform:order:refund:call:delete", name = "删除")
    public Result<?> delete(@PathVariable("id") String id) {
        final StartOrderRefundCallLogEntity entity = platformConfigService.getById(id);
        if (entity == null) return Result.ok();
        platformConfigService.removeById(id);
        return Result.ok();
    }


}
